/* EasyCODE V8 */
/* EasyCODE ( 0 */
#include "JI2C.h"
#include "MS5611.h"
/* EasyCODE ( 0 
unsigned short MS5611Read(unsigned char address) */
/* EasyCODE F */
unsigned short MS5611Read(unsigned char address)
{
    unsigned short data;
    
    i2c_start();
    i2c_write(MS5611_W);	// write 0xEC
    i2c_write(address);	// write register address
    i2c_stop();
    
    i2c_start();
    i2c_write(MS5611_R);	// write 0xED
    data = ((i2c_read())<<8);	// Get MSB result
    i2c_ack();
    data += (i2c_read());	// Get LSB result
    i2c_nack();
    i2c_stop();
    return data;
}

/* EasyCODE ) */
/* EasyCODE ( 0 
void MS5611Write(unsigned char address, unsigned char data) */
/* EasyCODE F */
void MS5611Write(unsigned char address, unsigned char data)
{
    i2c_start();
    i2c_write(MS5611_W);	// write 0xD2
    i2c_write(address);	// write register address
    i2c_write(data);
    i2c_stop();
}

/* EasyCODE ) */
/* EasyCODE ( 0 
void MS5611(unsigned char address) */
/* EasyCODE F */
void MS5611(unsigned int *data)
{
    i2c_start();
    i2c_write(MS5611_W);	// write 0xD0
    i2c_write(MS5611_ADC);	// write register address
    i2c_stop();
    
    i2c_start();
    i2c_write(MS5611_R);	// write 0xD1
    
    *data=((i2c_read())<<16);
    i2c_ack();
    *data+=((i2c_read())<<8);
    i2c_ack();
    *data+=(i2c_read());
    i2c_nack();
    i2c_stop();
}

/* EasyCODE ) */
/* EasyCODE ( 0 
void MS5611Command(unsigned char command) */
/* EasyCODE F */
void MS5611Command(unsigned char command)
{
    i2c_start();
    i2c_write(MS5611_W);	// write 0xEC
    i2c_write(command);	// write register address
    i2c_stop();
}

/* EasyCODE ) */
/* EasyCODE ) */
